﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MINERP.COM;
using System.Collections;

namespace MINERP.DAL.CommonDAL
{
    /// <summary>
    /// 委外记录表
    /// </summary>
    public class OutProcessRecordDAL : DALBase
    {
        /// <summary>
        /// 根据orderInfo的barcode找到此产品的分配记录
        /// </summary>
        /// <param name="barCode"></param>
        /// <returns>如果此产品还未分配就返回NULL</returns>
        public OutProcessRecord GetEntityByBarCode(string barCode)
        {
            orderInfo oi = DataEntites.orderInfo.Where(p => p.OrderProductCode == barCode).FirstOrDefault();
            if (oi != null)
            {
                oi.OutProcessRecord.Load();
                return oi.OutProcessRecord.Where(o => o.Status == (int)OutProcessRecordStatus.OutWaitFenDui).FirstOrDefault();
            }
            else
                return null;
        }

        public OutProcessRecord GetOneByOrderProductId(int OrderProductId)
        {
            return DataEntites.OutProcessRecord.First(p => p.orderInfo.OrderProductId == OrderProductId);
        }

        public void Delete(OutProcessRecord outRecord)
        {
            DataEntites.DeleteObject(outRecord);
        }
        public OutShopBillDetail GetDetail(int inorderid)
        {
            //string orderid=inorderid.ToString(),
            string barcode = "2"+string.Format("{0:D9}", inorderid);
            return DataEntites.OutShopBillDetail.FirstOrDefault(p =>p.OrderProductCode==barcode);
        }
        public void DelOutShopBillDetail(OutShopBillDetail inorderid)
        {

            DataEntites.DeleteObject(inorderid);
            //DataEntites.SaveChanges();
        }
    }
}
